home *** CD-ROM | disk | FTP | other *** search
/ Compendium Deluxe 1 / LSD Compendium Deluxe 1.iso / a / programming / assembly / ls55+44.lha / ls44.asm < prev    next >
Encoding:
Assembly Source File  |  1993-07-11  |  5.7 KB  |  311 lines

  1. * * * * * * * * * * * * * * * * * * * * * * * * *
  2. * ls.asm                    *
  3. * v4.4                        *
  4. * Jörgen Grahn                    *
  5. *                        *
  6. * 910718 ... 921116 ... 921221 ...        *
  7. * 921231 ... 930101 ... 930711            *
  8. *                        *
  9. * * * * * * * * * * * * * * * * * * * * * * * * *
  10. *                        *
  11. * History:                    *
  12. *                        *
  13. * [...]                        *
  14. *                        *
  15. * v4.2    (11.7.93)                *
  16. *    Fixed silly, horrible reentrancy bug by *
  17. *    replacing the BSS hunk with a dynamic    *
  18. *    allocation. This made the program    *
  19. *    8 bytes smaller.            *
  20. *                        *
  21. * v4.3    (11.7.93)                *
  22. *    Fixed memory location zero bug.    Ls    *
  23. *    would try to allocate $ABADCAFE memory    *
  24. *    or something like that if MungWall was    *
  25. *    active - thanks, Carolyn!        *
  26. *                        *
  27. * v4.4    (11.7.93)                *
  28. *    Fixed another memory location zero bug,    *
  29. *    an old one this time. Ls would not list    *
  30. *    current directory if given no argument    *
  31. *    with MungWall active.            *
  32. *                        *
  33. * * * * * * * * * * * * * * * * * * * * * * * * *
  34.  
  35. ABSEXECBASE        EQU 4
  36. MEMF_ANY        EQU 0
  37. SHARED_LOCK        EQU -2
  38. ERROR_DIR_NOT_FOUND    EQU 204
  39. ERROR_NO_MORE_ENTRIES    EQU 232
  40. SIGBREAKF_CTRL_C    EQU $00001000
  41. fib_SIZEOF        EQU 260
  42. fib_DIRENTRYTYPE    EQU 4            * <0 = dir, >0 = fil
  43. fib_FILENAME        EQU 8
  44.  
  45.     INCLUDE "offsets204.i"
  46.  
  47. libcall    MACRO
  48.     jsr _LVO\1(a6)
  49.     ENDM
  50.  
  51. *************************************************
  52.  
  53.     OFFSET    0
  54. ra_array:
  55.     ds.l    1
  56. *    CNOP    0,4
  57. fib:    ds.b    fib_SIZEOF        * FileInfoBlock
  58.     ds.l    0
  59. *    CNOP    0,2
  60. file:    ds.b    4+30+4+1+1        * Room for:
  61.                     * a) Escape sequence
  62.                     * b) 30 byte filename
  63.                     * c) Escape sequence
  64.                     * d) one space
  65.                     * e) terminating NULL byte
  66. blocksize:
  67.  
  68. *************************************************
  69.  
  70.     CSECT "text",code
  71.  
  72. entrypoint:
  73.     movem.l    d1-d7/a0-a6,-(sp)
  74.  
  75.     move.l    ABSEXECBASE.w,a6
  76.  
  77.     move.l    #blocksize,d0
  78.     move.l    #MEMF_ANY,d1
  79.     libcall    AllocVec            * Allocate memory
  80.     move.l    d0,a4                * to play with...
  81.     beq    exit
  82.  
  83.     lea    dosname(pc),a1
  84.     moveq    #36,d0
  85.  
  86.     libcall    OpenLibrary
  87.     move.l    d0,a6
  88.     beq    freemem
  89.  
  90.     * We now have DosBase in a6, and "BSS" in a4.
  91.  
  92.     lea    ra_array(a4),a0
  93.     lea.l    zerostring(pc),a1        * Point the argument to fill
  94.     move.l    a1,(a0)                * in to a zero lenght string
  95.     move.l    a0,d2                * to be used as default.
  96.     lea    template(pc),a0
  97.     move.l    a0,d1
  98.     clr.l    d3
  99.  
  100.     libcall    ReadArgs
  101.     move.l    d0,a5                * Save the ReadArgs struct
  102.     bne.s    readargs_ok
  103.  
  104.     bsr    printioerr
  105.     bra    closedos
  106.  
  107. readargs_ok:                    * Dos in a6, ReadArgs in a5.
  108.  
  109.     move.l    ra_array(a4),d1            * Program argument string
  110.     move.l    #SHARED_LOCK,d2
  111.     libcall    Lock
  112.     move.l    d0,d7
  113.     bne.s    locked_ok
  114.  
  115.     bsr    printioerr
  116.     bra.s    freeargs
  117.  
  118. locked_ok:                * Dos - a6    ReadArgs - a5
  119.                     * Lock - d7    "BSS" - a4
  120.     lea    fib(a4),a3        * fib - a3
  121.  
  122.     move.l    d7,d1
  123.     move.l    a3,d2
  124.     libcall    Examine
  125.     tst.l    d0
  126.     beq.s    examine_failed
  127.     tst.l    fib_DIRENTRYTYPE(a3)    * Did we Lock() a file?
  128.     bpl.s    dir_examined
  129.  
  130. examine_on_file:
  131.     moveq    #0,d2
  132.     move.l    #ERROR_DIR_NOT_FOUND,d1
  133.     libcall    PrintFault
  134.     bra.s    freelock
  135.  
  136.     * d3 holds how many names have been written to this row.
  137.     * d4 holds the _real_ position on the row.
  138. dir_examined:
  139.     clr.l    d3
  140.     move.l    d3,d4
  141.  
  142. exnext:
  143.     lea    file(a4),a2
  144.     bsr    readname        * fib (a3) file (a2) lock (d7)
  145.                     * nr_names (d3) pos (d4)
  146.     tst.l    d0
  147.     bne.s    print_file
  148.     bsr.s    newline            * Put us on new line...
  149.     bra.s    no_more_files        * ...and close down
  150.  
  151. print_file:
  152.     move.l    a2,a0
  153.     bsr.s    putstr
  154.  
  155.     move.l    #SIGBREAKF_CTRL_C,d1
  156.     libcall    CheckSignal        * Check for ^C.
  157.     tst.l    d0
  158.     beq.s    exnext
  159.  
  160.     bsr.s    newline            * Put us on new line...
  161.     lea    breakstring(pc),a0
  162.     bsr.s    putstr
  163.     bra.s    freelock
  164.  
  165. examine_failed:        * Sort of cheating, but it works. Putting this here
  166.             * is exactly the same as calling printioerr,
  167.             * as ENME will never happen.
  168. no_more_files:
  169.     libcall    IoErr            * Should an error be printed?
  170.     cmpi.l    #ERROR_NO_MORE_ENTRIES,d0
  171.     beq.s    freelock
  172.     bsr    printioerr
  173.  
  174. freelock:
  175.     move.l    d7,d1
  176.     libcall    UnLock
  177.  
  178. freeargs:
  179.     move.l    a5,d1
  180.     libcall    FreeArgs
  181.  
  182. closedos:
  183.     move.l    a6,a1
  184.     move.l    ABSEXECBASE.w,a6
  185.     libcall    CloseLibrary
  186.  
  187. freemem:
  188.     move.l    a4,a1
  189.     move.l    ABSEXECBASE.w,a6
  190.     libcall    FreeVec
  191.  
  192. exit:
  193.     moveq    #0,d0
  194.     movem.l    (sp)+,d1-d7/a0-a6
  195.     rts
  196.  
  197. *************************************************
  198. *
  199. * Puts us on a new line, if necessary.
  200. * Destroys d0-d2/a0-a1.
  201.  
  202. newline:
  203.     tst.l    d4
  204.     beq.s    1$
  205.     lea    newlinestr(pc),a0
  206.     bsr.s    putstr
  207. 1$:    rts
  208.  
  209. *************************************************
  210. *
  211. * fputs(string (a0))
  212. * Förstör d0-d1/d5/a0-a1
  213. *
  214.  
  215. putstr:
  216.     move.l    a0,-(sp)
  217.     libcall    Output
  218.     move.l    d0,d5
  219.     beq.s    1$
  220.     move.l    (sp)+,d1
  221.     libcall    PutStr
  222.     move.l    d5,d1
  223.     libcall    Flush
  224. 1$:    rts
  225.  
  226. *************************************************
  227. *
  228. * Reads a filename for printing.
  229. *
  230. * a2 - 'file' array
  231. * a3 - fib
  232. * d7 - lock
  233. * d3 - number of names previous on row (altered [0..3])
  234. * d4 - position on row (altered)
  235. *
  236. * returns 0 if end of names.
  237.  
  238. readname:
  239.     movem.l    d1-d2/d5-d7/a0-a6,-(sp)
  240.  
  241.     move.l    d7,d1
  242.     move.l    a3,d2
  243.     libcall    ExNext
  244.     tst.l    d0
  245.     beq.s    sorry
  246.  
  247.     lea    fib_FILENAME(a3),a0
  248.     move.l    a2,a1
  249.  
  250.     tst.l    fib_DIRENTRYTYPE(a3)
  251.     bmi.s    1$
  252.     move.l    #$9b33336d,(a1)+        * ESC[33m - highlight mode
  253.  
  254. 1$:    move.b    (a0)+,d0
  255.     beq.s    name_filled
  256.     addq.l    #1,d4
  257.     move.b    d0,(a1)+
  258.     bra.s    1$
  259.  
  260. name_filled:
  261.     tst.l    fib_DIRENTRYTYPE(a3)
  262.     bmi.s    fill_spaces
  263.     move.b    #$9b,(a1)+        * reset highlight mode
  264.     move.b    #'3',(a1)+
  265.     move.b    #'1',(a1)+
  266.     move.b    #'m',(a1)+
  267.  
  268. fill_spaces:
  269.     move.b    positions(pc,d3),d0
  270. 1$:    move.b    #' ',(a1)+
  271.     addq.l    #1,d4
  272.     cmp.b    d0,d4
  273.     ble.s    1$
  274.  
  275. done_spaces:
  276.     addq.l    #1,d3
  277.     cmpi.w    #4,d3
  278.     bne.s    1$
  279.  
  280.     clr.l    d3
  281.     move.l    d3,d4
  282.     move.b    #10,(a1)+
  283. 1$:    move.b    #0,(a1)
  284.  
  285. sorry:    movem.l    (sp)+,d1-d2/d5-d7/a0-a6
  286.     rts
  287.  
  288. *************************************************
  289.  
  290. * Skriver ut IoErr().
  291. * Förstör a0-a1/d0-d2.
  292. *
  293. printioerr:
  294.     libcall    IoErr
  295.     moveq    #0,d2
  296.     move.l    d0,d1
  297.     libcall    PrintFault
  298.     rts
  299.  
  300. *************************************************
  301.  
  302. positions:    dc.b    16,32,48,64
  303. template:    dc.b    'DIR',0
  304. dosname:    dc.b    'dos.library',0
  305. versionstring:    dc.b    '$VER: ls 4.4 (11.7.93) Jörgen Grahn',0
  306. breakstring:    dc.b    '***Break'
  307. newlinestr:    dc.b    10
  308. zerostring:    dc.b    0
  309.  
  310.     END
  311.